package it.unicam.cs.cosy.bioshape.core.behaviours;

import java.io.Serializable;

/**
 * Generic behaviour of a shape. All the Shape Calculus behaviour operators
 * derive from this base class.
 * 
 * @author Federico Buti
 */
public abstract class Behaviour implements Serializable {

	@Override
	public int hashCode() {
		final int prime = 92821;
		int result = 1;
		result = prime * result
				+ ((component == null) ? 0 : component.hashCode());
		result = prime * result + ((label == null) ? 0 : label.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Behaviour other = (Behaviour) obj;
		if (component == null) {
			if (other.component != null)
				return false;
		} else if (!component.equals(other.component))
			return false;
		if (label == null) {
			if (other.label != null)
				return false;
		} else if (!label.equals(other.label))
			return false;
		return true;
	}

	/** Auto-generated serialID */
	private static final long serialVersionUID = 2631907647725632762L;

	Behaviour component;

	protected String label;

	/**
	 * @return The label of the process behaviour
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * @return The {@code Behaviour} following this one
	 */
	public Behaviour getNext() {
		return component;
	}

	/**
	 * Checks if the process is guarded, i.e. an action occurs as first
	 * behaviour
	 * 
	 * @return {@code true} if the process is guarded {@code false} otherwise
	 */
	public boolean isGuarded() {
		return true;
	}

	/**
	 * Update the linkage of this variable to the real pointed process.
	 * 
	 * @param component
	 *            The real {@code behaviour} pointed by this variable
	 */
	void setNext(Behaviour component) {
		this.component = component;
	}

	/**
	 * Returns the behaviour associated with this behaviour. Basically it
	 * returns a reference to the <i>same</i> object apart from the
	 * {@code Variable} case.
	 * 
	 * @return this exact {@code Behaviour} in most cases except
	 *         {@code Variable}
	 * 
	 * @see Variable
	 */
	public Behaviour getBehaviour() {
		return this;
	}

}